package cn.agiledata.bank.common.dao;

import java.util.List;

import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.hibernateBean.Account;
import cn.agiledata.bank.hibernateBean.SubAccount;
import cn.agiledata.bank.hibernateBean.SysParameter;
import cn.agiledata.bank.hibernateBean.Sysbook;
import com.vnv.infrastructure.logic.IPBHibernate3BaseMgr;

public class SysTemplate extends IPBHibernate3BaseMgr{
	
	public List getAllSysParameter(Long SubAccountId,String type){
		List resultList =getHibernateTemplate()
		.findByNamedQuery("getParameterList",
				new Object[]{SubAccountId,SubAccountId,type});
		return resultList;
	}
	
	public SysParameter getFeeMode(Long SubAccountId){
		List parameterList = 
			this.getAllSysParameter(SubAccountId,"FEE_MODE");
		return (SysParameter)parameterList.get(0);
	}
	
	public SysParameter getWithDrawFee(Long SubAccountId){
		List parameterList = 
			this.getAllSysParameter(SubAccountId,"WITHDRAW_FEE");
		return (SysParameter)parameterList.get(0);		
	}
	
	public Sysbook getSysbookById(String id){
		return (Sysbook)getHibernateTemplate().get(Sysbook.class,new Long(id));
	}
	
	public void saveAccount(Account acco){
		SubAccount defaultSubAccount = new SubAccount();
		defaultSubAccount.setAccountId("test");
		defaultSubAccount.setAccountName("test");
		
	}
	
	public SysParameter getMonthScoreLimite(Long accountId) {
		List parameterList = 
			this.getAllSysParameter(accountId,Constant.SYS_PARAM_MONTH_SCORE_LIMITE);
		return (SysParameter)parameterList.get(0);		
	}
	
	/**
	 * 根据类型查询系统参数
	 * 
	 * @param paramType
	 * @return
	 */
	public SysParameter getParamByType(String paramType) {
		String strOql = "select sp from SysParameter sp where sp.parmType='"
				+ paramType + "'";

		List listResult = getHibernateTemplate().find(strOql);
		
		if(listResult == null || listResult.size() == 0) {
			return null;
		}
		
		return (SysParameter)listResult.get(0);
	}
	
}
